<template>
    <div v-if="isAuth(['ROOT', 'MEDICAL_DEPT:SELECT',])">
		<el-form :inline="true" :model="dataForm" :rules="dataRule" ref="dataForm">
		    <el-form-item>
		        <el-select
		            v-model="dataForm.status"
		            class="input"
		            placeholder="操作类型"
		            size="medium"
		            clearable="clearable"
		        >
		            <el-option label="出库" value="1" />
		            <el-option label="入库" value="2" />
		        </el-select>
		    </el-form-item>
			<el-form-item>
			    <el-button type="primary" @click="searchHandle()">查询</el-button>
			</el-form-item>
		</el-form>
        <el-table
            :data="dataList"
            border
            v-loading="dataListLoading"
            @selection-change="selectionChangeHandle"
            :cell-style="{ padding: '3px 0' }"
            style="width: 100%;"
        >
            <el-table-column type="index" header-align="center" align="center" width="100" label="序号">
                <template #default="scope">
                    <span>{{ (pageIndex - 1) * pageSize + scope.$index + 1 }}</span>
                </template>
            </el-table-column>
			<el-table-column header-align="center" align="center" label="药品编号" min-width="180">
			    <template #default="scope">
			        <span>{{ scope.row.drugid }}</span>
			    </template>
			</el-table-column>
			<el-table-column header-align="center" align="center" label="药品名称" min-width="200">
			    <template #default="scope">
			        <span>{{ scope.row.drugname }}</span>
			    </template>
			</el-table-column>
			<el-table-column header-align="center" align="center" label="操作数量" min-width="120">
			    <template #default="scope">
			        <span>{{ scope.row.drugnum }}</span>
			    </template>
			</el-table-column>
			<el-table-column header-align="center" align="center" label="操作者" min-width="120">
			    <template #default="scope">
			        <span>{{ scope.row.user }}</span>
			    </template>
			</el-table-column>
			<el-table-column prop="status" header-align="center" align="center" label="操作类型" min-width="120" />
			<el-table-column header-align="center" align="center" label="操作时间" min-width="120">
			    <template #default="scope">
			        <span>{{ scope.row.createtime }}</span>
			    </template>
			</el-table-column>
			<el-table-column header-align="center" align="center" label="备注" min-width="200">
			    <template #default="scope">
			        <span>{{ scope.row.remark }}</span>
			    </template>
			</el-table-column>
			</el-table>
        <el-pagination
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
            :current-page="pageIndex"
            :page-sizes="[10, 20, 50]"
            :page-size="pageSize"
            :total="totalCount"
            layout="total, sizes, prev, pager, next, jumper"
        ></el-pagination>

        <add-or-update ref="addOrUpdate" @refreshDataList="loadDataList"></add-or-update>
    </div>
</template>

<script>
export default {
    data: function() {
        return {
            dataForm: {
                status: ''
            },
            dataList: [],
            pageIndex: 1,
            pageSize: 10,
            totalCount: 0,
            dataListLoading: false,
            dataListSelections: [],
            dataRule: {
                
            }
        };
    },
    methods: {
        loadDataList: function() {
            let that = this;
            that.dataListLoading = true;
            let data = {
                page: that.pageIndex,
                length: that.pageSize,
				status: that.dataForm.status == '' ? null : that.dataForm.status
            };
        
            that.$http('/drugoperate/searchoperateByPage', 'POST', data, true, function(resp) {
                let result = resp.result;
				let temp = {
				    '1': '出库',
				    '2': '入库'
				};
				for (let one of result.list) {
				    one.status = temp[one.status + ''];
				}
                that.dataList = result.list;
                that.totalCount = result.totalCount;
                that.dataListLoading = false;
            });
        },
		sizeChangeHandle: function(val) {
		    this.pageSize = val;
		    this.pageIndex = 1;
		    this.loadDataList();
		},
		currentChangeHandle: function(val) {
		    this.pageIndex = val;
		    this.loadDataList();
		},
		searchHandle: function() {
		    this.$refs['dataForm'].validate(valid => {
		        if (valid) {
		            this.$refs['dataForm'].clearValidate();
		            if (this.dataForm.status == '') {
		                this.dataForm.status = null;
		            }
		            if (this.pageIndex != 1) {
		                this.pageIndex = 1;
		            }
		            this.loadDataList();
		        } else {
		            return false;
		        }
		    });
		},
		selectionChangeHandle: function(val) {
		    this.dataListSelections = val;
		},
		selectable: function(row, index) {
		    if (row.subs > 0) {
		        //含有隶属诊室，该行科室记录的复选框被禁用
		        return false;
		    }
		    return true;
		},

    },
    created: function() {
        this.loadDataList();
    }
};
</script>

<style></style>
